package com.ler.yrmall.search.rpc;

import com.ler.yrmall.search.api.SearchApi;
import com.ler.yrmall.search.dto.SearchResultDTO;
import com.ler.yrmall.search.dto.SkuEsModelDTO;
import com.ler.yrmall.search.request.SpuSearchRequest;
import com.ler.yrmall.search.service.SpuSearchService;
import com.ler.yrmall.search.service.impl.ProductServiceImpl;
import com.ler.yrmall.basic.Result;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Leron
 * @version 1.0
 */
@Service
@DubboService
public class SearchApiImpl implements SearchApi {

    @Resource
    private ProductServiceImpl productSaveService;

    @Resource
    private SpuSearchService spuSearchService;

    @Override
    public Result<Boolean> saveSku(List<SkuEsModelDTO> skuList) {
        return Result.ok(productSaveService.productSale(skuList));
    }

    @Override
    public Result<Boolean> deleteSku(List<Long> skuIds) {
        return Result.ok(productSaveService.productSoldOut(skuIds));
    }

    @Override
    public Result<SearchResultDTO> searchSpu(SpuSearchRequest searchRequest) {
        return Result.ok(spuSearchService.search(searchRequest));
    }
}
